<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Snapshot retention | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'slm-retention.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/slm-retention.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/slm-retention.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/slm-retention.html" rel="nofollow" target="_blank">../en/slm-retention.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="snapshot-restore.html">Snapshot and restore</a></span>
»
<span class="breadcrumb-link"><a href="snapshot-lifecycle-management.html">SLM: Manage the snapshot lifecycle</a></span>
»
<span class="breadcrumb-node">Snapshot retention</span>
</div>
<div class="navheader">
<span class="prev">
<a href="slm-and-security.html">« Security and SLM</a>
</span>
<span class="next">
<a href="secure-cluster.html">Secure a cluster »</a>
</span>
</div>
<div class="section xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="slm-retention"></a>Snapshot retention<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/slm/slm-retention.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>
<p>You can include a retention policy in an SLM policy to automatically delete old snapshots.
Retention runs as a cluster-level task and is not associated with a particular policy’s schedule.
The retention criteria are evaluated as part of the retention task, not when the policy executes.
For the retention task to automatically delete snapshots,
you need to include a <a class="xref" href="slm-api-put-policy.html#slm-api-put-retention"><code class="literal">retention</code></a> object in your SLM policy.</p>
<p>To control when the retention task runs, configure
<a class="xref" href="slm-settings.html#slm-retention-schedule"><code class="literal">slm.retention_schedule</code></a> in the cluster settings.
You can define the schedule as a periodic or absolute <a class="xref" href="trigger-schedule.html#schedule-cron" title="Cron schedule">cron schedule</a>.
The <a class="xref" href="slm-settings.html#slm-retention-duration"><code class="literal">slm.retention_duration</code></a> setting limits how long
SLM should spend deleting old snapshots.</p>
<p>You can update the schedule and duration dynamically with the
<a class="xref" href="cluster-update-settings.html" title="Cluster update settings API">update settings</a> API.
You can run the retention task manually with the
<a class="xref" href="slm-api-execute-retention.html" title="Execute snapshot retention policy API">execute retention </a> API.</p>
<p>The retention task only considers snapshots initiated through SLM policies,
either according to the policy schedule or through the
<a class="xref" href="slm-api-execute-lifecycle.html" title="Execute snapshot lifecycle policy API">execute lifecycle</a> API.
Manual snapshots are ignored and don’t count toward the retention limits.</p>
<p>To retrieve information about the snapshot retention task history,
use the  <a class="xref" href="slm-api-get-stats.html" title="Get snapshot lifecycle stats API">get stats</a> API:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /_slm/stats</pre>
</div>
<div class="console_widget" data-snippet="snippets/1217.console"></div>
<p>The response includes the following statistics:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "retention_runs": 13, <a id="CO463-1"></a><i class="conum" data-value="1"></i>
  "retention_failed": 0, <a id="CO463-2"></a><i class="conum" data-value="2"></i>
  "retention_timed_out": 0, <a id="CO463-3"></a><i class="conum" data-value="3"></i>
  "retention_deletion_time": "1.4s", <a id="CO463-4"></a><i class="conum" data-value="4"></i>
  "retention_deletion_time_millis": 1404,
  "policy_stats": [
    {
      "policy": "daily-snapshots",
      "snapshots_taken": 1,
      "snapshots_failed": 1,
      "snapshots_deleted": 0, <a id="CO463-5"></a><i class="conum" data-value="5"></i>
      "snapshot_deletion_failures": 0 <a id="CO463-6"></a><i class="conum" data-value="6"></i>
    }
  ],
  "total_snapshots_taken": 1,
  "total_snapshots_failed": 1,
  "total_snapshots_deleted": 0, <a id="CO463-7"></a><i class="conum" data-value="7"></i>
  "total_snapshot_deletion_failures": 0 <a id="CO463-8"></a><i class="conum" data-value="8"></i>
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO463-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Number of times retention has been run</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO463-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>Number of times retention failed while running</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO463-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>Number of times retention hit the <code class="literal">slm.retention_duration</code> time limit and had to stop before deleting all eligible snapshots</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO463-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p>Total time spent deleting snapshots by the retention process</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO463-5"><i class="conum" data-value="5"></i></a></p>
</td>
<td align="left" valign="top">
<p>Number of snapshots created by the "daily-snapshots" policy that have been deleted</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO463-6"><i class="conum" data-value="6"></i></a></p>
</td>
<td align="left" valign="top">
<p>Number of snapshots that failed to be deleted</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO463-7"><i class="conum" data-value="7"></i></a></p>
</td>
<td align="left" valign="top">
<p>Total number of snapshots deleted across all policies</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO463-8"><i class="conum" data-value="8"></i></a></p>
</td>
<td align="left" valign="top">
<p>Total number of snapshot deletion failures across all policies</p>
</td>
</tr>
</table>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="slm-and-security.html">« Security and SLM</a>
</span>
<span class="next">
<a href="secure-cluster.html">Secure a cluster »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>